package com.bw.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.bw.mapper.TmsMapper;
import com.bw.service.TmsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author Lenovo
 * @date 2025年09月01日 14:33
 */
@RestController
public class TmsController {

    @Autowired
    private TmsMapper tmsMapper;

    @RequestMapping("/s1")
    public JSONObject select1(){
        JSONObject result = new JSONObject();
        result.put("status",0);
        result.put("msg","");

        JSONArray data = new JSONArray();
        result.put("data",data);

        List<Map<String, Object>> maps = tmsMapper.select1();
        Map<String,Object>map=maps.get(0);

        JSONObject col1 = new JSONObject();
        col1.put("name","当日完成运输次数");
        col1.put("value",map.get("cta"));

        JSONObject col2 = new JSONObject();
        col2.put("name","当日完成运输里程");
        col2.put("value",map.get("ctb"));

        JSONObject col3 = new JSONObject();
        col3.put("name","当日完成运输时长");
        col3.put("value",map.get("ctc"));

        data.add(col1);
        data.add(col2);
        data.add(col3);

        return result;
    }

    @RequestMapping("/s2")
    public JSONObject select2(){
        JSONObject result = new JSONObject();
        result.put("status",0);
        result.put("msg","");

        JSONArray data = new JSONArray();
        result.put("data",data);

        List<Map<String, Object>> maps = tmsMapper.select2();
        Map<String,Object>map=maps.get(0);

        result.put("data",map.get("cta"));

        return result;
    }

    @RequestMapping("/s3")
    public JSONObject select3(){
        JSONObject result = new JSONObject();
        result.put("status",0);
        result.put("msg","");
        JSONObject data = new JSONObject();
        result.put("data",data);
        JSONArray columns = new JSONArray();
        JSONArray rows = new JSONArray();
        data.put("columns",columns);
        data.put("rows",rows);


        JSONObject col1 = new JSONObject();
        col1.put("name","序号");
        col1.put("id","id");

        JSONObject col2 = new JSONObject();
        col2.put("name","名称");
        col2.put("id","name");

        JSONObject col3 = new JSONObject();
        col3.put("name","完成时长");
        col3.put("id","cta");

        columns.add(col1);
        columns.add(col2);
        columns.add(col3);

        List<Map<String,Object>> maps=tmsMapper.select3();
        for (Map<String, Object> map : maps) {
            JSONObject row = new JSONObject();
            row.put("id",map.get("id"));
            row.put("name",map.get("name"));
            row.put("cta",map.get("cta"));
            rows.add(row);
        }

        return result;
    }

    @RequestMapping("/s4")
    public JSONObject select4(){
        JSONObject result = new JSONObject();
        result.put("status",0);
        result.put("msg","");
        JSONObject data = new JSONObject();
        result.put("data",data);


        JSONArray categories = new JSONArray();
        JSONArray series = new JSONArray();
        data.put("categories",categories);
        data.put("series",series);

        List<Map<String,Object>> maps=tmsMapper.select4();

        JSONObject series_row1 = new JSONObject();
        series_row1.put("name","城市");

        series.add(series_row1);

        JSONArray series_row1_data = new JSONArray();
        series_row1.put("data",series_row1_data);
        for (Map<String, Object> map : maps) {
            categories.add(map.get("org_name"));
            series_row1_data.add(map.get("cta"));
        }

        return result;
    }

    @RequestMapping("/s5")
    public JSONObject select5(){
        JSONObject result = new JSONObject();
        result.put("status",0);
        result.put("msg","");
        JSONArray data = new JSONArray();
        result.put("data",data);
        List<Map<String, Object>> maps = tmsMapper.select5();
        for (Map<String, Object> map : maps) {
            JSONObject row = new JSONObject();
            row.put("name",map.get("name"));
            row.put("value",map.get("cta"));
            data.add(row);
        }

        return result;
    }
    
    @RequestMapping("/s6")
    public JSONObject select6(){
        JSONObject result = new JSONObject();
        result.put("status",0);
        result.put("msg","");
        JSONArray data = new JSONArray();
        result.put("data",data);
        
        List<Map<String,Object>>maps=tmsMapper.select6();
        Map<String, Object> map = maps.get(0);

        JSONObject col1 = new JSONObject();
        col1.put("name","接单数");
        col1.put("value",map.get("cta"));

        JSONObject col2 = new JSONObject();
        col2.put("name","发单数");
        col2.put("value",map.get("ctb"));

        JSONObject col3 = new JSONObject();
        col3.put("name","完成运单数");
        col3.put("value",map.get("ctc"));

        data.add(col1);
        data.add(col2);
        data.add(col3);
        return result;
    }

    @RequestMapping("/s7")
    public JSONObject select7(){
        JSONObject retult = new JSONObject();
        retult.put("status",0);
        retult.put("msg","");
        List<Map<String,Object>>maps=tmsMapper.select7();
        Map<String, Object> map = maps.get(0);
        retult.put("data",map.get("cta"));
        return retult;
    }

    @RequestMapping("/s8")
    public  JSONObject select8(){
        JSONObject result = new JSONObject();
        result.put("status",0);
        result.put("msg","");
        JSONArray data = new JSONArray();
        result.put("data",data);

        JSONArray mapData = new JSONArray();


        return result;
    }

    @RequestMapping("/s9")
    public JSONObject select9(){
        JSONObject result = new JSONObject();
        result.put("status",0);
        result.put("msg","");
        JSONObject data = new JSONObject();
        result.put("data",data);
        JSONArray columns = new JSONArray();
        JSONArray rows = new JSONArray();
        data.put("columns",columns);
        data.put("rows",rows);

        JSONObject col1 = new JSONObject();
        col1.put("name","序号");
        col1.put("id","id");

        JSONObject col2 = new JSONObject();
        col2.put("name","名字");
        col2.put("id","name");

        JSONObject col3 = new JSONObject();
        col3.put("name","完运时长");
        col3.put("id","cta");

        columns.add(col1);
        columns.add(col2);
        columns.add(col3);

        List<Map<String,Object>>maps=tmsMapper.select9();
        for (Map<String, Object> map : maps) {
            JSONObject row = new JSONObject();
            row.put("id",map.get("id"));
            row.put("name",map.get("name"));
            row.put("cta",map.get("cta"));
            rows.add(row);
        }

        return result;
    }
}
